<template>
	<view>
		<u-form labelPosition="left" :model="form" ref="form1">
			<u-form-item prop="name" borderBottom ref="item1">
				<h2 style="color:#eee;margin: 0 auto;">手机阅卷</h2>
			</u-form-item>
			<u-form-item prop="name" borderBottom ref="item1">
				<u-input v-model="form.name" type="text" clearable border="bottom" :color="color"
					placeholder="姓名"></u-input>
			</u-form-item>
			<u-form-item prop="phone">
				<u-input v-model="form.phone" type="text" clearable border="bottom" :color="color"
					placeholder="手机号"></u-input>
			</u-form-item>
			<u-form-item>
				<u-button text="登录" style="margin-top: 20px;"
					color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"
					@click="toKaoshi(true)"></u-button>
			</u-form-item>
			<!-- <u-form-item>
				<u-button text="测试页面" style="margin-top: 20px;"
					color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"
					@click="toTest"></u-button>
			</u-form-item> -->
		</u-form>
		<iceMessage :msgParams="msgParams.value" @iceClose="msgParams.isOpen=false" />
		<iceDialog :msgParams="msgParams2.value" mode="input" @iceClose="iceClose" />
		<iceLoading :title="`正在登录`" :show="show" />
	</view>
</template>
<script setup>
	import {
		reactive,
		ref
	} from 'vue'
	import {
		iceGetStorage,
		iceSetStorage
	} from '../../utils/common';
	import iceLoading from '@/components/widget/iceLoading.vue';
	import {
		// postEditPassword,
		postReadoverLogin
	} from '../../src/api/prePaper.js';
	const color = ref('#dadbde');
	const msgParams = reactive({
		value: {
			msgType: '',
			messageText: '',
			isOpen: false
		}
	})
	const msgParams2 = reactive({
		value: {
			title: '',
			placeholder: '',
			isOpen: false
		}
	})
	const form = reactive({})
	const iceGetStorages = async () => {
		// form.username = await iceGetStorage('username')
		// form.password = await iceGetStorage('password')
		form.username = 'admin'
		form.password = 'adminhui'
		console.log(form);
	}
	iceGetStorages()
	const uid = ref('')
	const show = ref(false)
	const iceClose = (e) => {
		const data = {
			uid: uid.value,
			pwd: e,
			pwd_confirm: e,
			old_pwd: form.password,
		}
		postEditPassword(data).then(res => {
			msgParams.value = {
				popupType: 'message',
				msgType: 's',
				messageText: res.msg,
				isOpen: true
			}
			form.password = e
		}).catch(err => {
			msgParams.value = {
				popupType: 'message',
				msgType: 'e',
				messageText: err,
				isOpen: true
			}
		})
	}
	const toTest = () => {
		uni.navigateTo({
			url: '/pages/test/index'
		})
	}
	const toKaoshi = (bool) => {
		show.value = true
		const sto2 = setTimeout(() => {
			postReadoverLogin(form).then(res => {
				if (res.code == 0) {
					// 阅卷是否保存登录信息，待定
					// iceSetStorage('userId', res.data.uid)
					uni.redirectTo({
						url: `/pages/kaoshiList/index`
					})
					show.value = false
				}
			})
			clearTimeout(sto2)
		}, 2000)
	}
</script>
<style lang="scss" scoped>
	.u-form {
		width: 400rpx;
		margin: 0 auto;

		.custom-style {
			width: 1400rpx;
		}
	}
</style>